/**
 * @author Ronen Pinko
 */
package il.ac.bgu.cs.heuristics.graph.pddl.parser.types;

public final class Type {
	public final static Type	OBJECT	= new Type("object", null);
	private final String		name;
	private final Type			parent;

	public Type(String name, Type parent) {
		this.name = name;
		this.parent = parent;
	}

	public static Type from(String name) {
		return new Type(name, OBJECT);
	}

	public String name() {
		return name;
	}

	public Type parent() {
		return parent;
	}

	@Override
	public String toString() {
		return "Type(" + name + ":" + parent.name + ")";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Type other = (Type) obj;
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}

}